<?php
declare (strict_types=1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Goods extends Model
{
    protected $table = 'ctmon_goods';
    protected $schema = [
        'goods_id' => 'int',
        'cat_id' => 'int',
        'brand_id' => 'int',
        'goods_type' => 'int',
        'goods_sn' => 'varchar',// 系列
        'goods_name' => 'varchar',// 产品名称
        'goods_subname' => 'varchar',// 规格书
        'click_count' => 'int',
        'goods_number' => 'varchar',//功率
        'warn_number' => 'varchar',// 应用
        'goods_weight' => 'decimal',
        'weight_unit' => 'varchar',
        'market_price' => 'decimal',
        'shop_price' => 'decimal',
        'promote_price' => 'decimal',
        'promote_start_date' => 'timestamp',
        'promote_end_date' => 'timestamp',
        'tag' => 'varchar',
        'goods_desc' => 'text',
        'goods_content' => 'text',
        'goods_thumb' => 'varchar',
        'goods_img' => 'varchar',
        'info_img' => 'varchar',
        'original_img' => 'varchar',
        'goods_video' => 'varchar',// 质保时间
        'info_tlp' => 'varchar',
        'is_on_sale' => 'bit',
        'is_alone_sale' => 'bit',
        'integral' => 'int',
        'add_time' => 'timestamp',
        'last_update' => 'timestamp',
        'sort_order' => 'int',
        'is_delete' => 'bit',
        'is_best' => 'bit',
        'is_new' => 'bit',
        'is_hot' => 'bit',
        'is_specials' => 'bit',
        'is_import' => 'bit',
        'is_promote' => 'bit',
        'give_integral' => 'int',
        'lowest_quantity' => 'int',
        'max_quantity' => 'int',
        'urlrewriter' => 'varchar',
        'pagetitle' => 'text',
        'pagekeywords' => 'text',
        'pagedesc' => 'text',
        'goods_relation' => 'varchar',
        'up_type' => 'varchar',
        'is_mobile' => 'bit',
        'goods_gg' => 'text',// 证书
        'down_id' => 'text',
        'goods_yy' => 'text',
        'is_moren' => 'bit',
        'filename' => 'varchar',
        'url' => 'varchar',
        'goods_field' => 'varchar',
        'photo' => 'varchar',
        'photo2' => 'varchar',
    ];
    protected $pk = 'goods_id';

    /**
     * 获取产品分类
     * @return \think\model\relation\HasOne
     */
    public function getCategory()
    {
        return $this->hasOne(GoodsCategory::class, 'cat_id', 'cat_id');
    }

    public function getDetails()
    {
        return $this->hasMany(GoodsDetails::class, 'goods_id', 'goods_id');
    }

    public function getGallery()
    {
        return $this->hasMany(GoodsGallery::class, 'goods_id', 'goods_id');
    }
}
